import { getRgb } from "../utils"
import { context } from "../context"

export function useAccentColor(name): [string, boolean] {
  const { resume: { customization } } = context

  const { layout, sectionOrder, colors } = customization
  const section = sectionOrder[layout.colsFromDetails[layout.detailsPosition]]
  if (colors.mode === 'simple') {
    return [getRgb((colors as Colors).strong.accentColor), true]
  }
  else {
    if (layout.detailsPosition === 'top') {
      if (name === 'resumeHeader') {
        return [getRgb((colors as Colors).light.accentColor), true]
      }
      return [getRgb((colors as Colors).strong.accentColor), true]
    }
    else {
      if (name === 'resumeHeader') {
        return [getRgb((colors as Colors).light.accentColor), true]
      }
      if (layout.detailsPosition === 'left') {
        if (section.leftSectionChildren && section.leftSectionChildren.includes(name)) {
          return [getRgb((colors as Colors).light.accentColor), false]
        }
        return [getRgb((colors as Colors).strong.accentColor), true]
      }
      if (layout.detailsPosition === 'right') {
        if (section.rightSectionChildren && section.rightSectionChildren.includes(name)) {
          return [getRgb((colors as Colors).light.accentColor), false]
        }
        return [getRgb((colors as Colors).strong.accentColor), true]
      }
    }
  }

  return ['', false]
}
